<template>
  <base-layout
     :dialog-title="dialogTitle"
    :dialog-visible="dialogVisible"
    dialog-width="600px"
    :page-show="pageShow"
    @dialog-close="dialogClose"
  >
    <template #toolPanel />
    <template #searchPanel>
      <search-panel :show-add-button="true" :show-search-button="true" labelWidth="45" @search="search" @insert="handleDataInsert" :left="true">
            <el-form-item label="号码:">
              <el-input v-model="filters.phone" style="width: 200px" placeholder="号码" />
            </el-form-item>
            <el-form-item label="备注:">
              <el-input v-model="filters.note" maxlength="100" clearable />
            </el-form-item>
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :current="start"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
        <template #action="{row}">
          <el-button size="small" round style="color:red;" @click="deletedRowtable(row)">删除</el-button>
        </template>
      </data-table>
    </template>

    <template #dialog>
      <el-form :model="form" label-width="100px" ref="form">
        <el-form-item label="充值号码" prop="phone">
          <el-input v-model="form.phone" placeholder="多个号码使用,分割 示例:18022224444,13566667777" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="note">
          <el-input v-model="form.note" auto-complete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align: center;">
        <el-button round size="small" @click.native="dialogVisible = false">取消</el-button>
        <el-button round size="small" type="primary" @click.native="onSubmit" >提交</el-button>
      </div>
    </template>

  </base-layout>
</template>

<script>
import baseMixin from '@/mixins/base'
import DialogDataForm from './components/DialogDataForm'
import { getBlacklistPage , updateBlacklist , deleteBlacklist} from '@/api/utilsapi'


export default {
  name: 'blacklist',
  components: { DialogDataForm },
  mixins: [
    baseMixin({
      idName: 'id',
      findData: getBlacklistPage,
      deleteDataRow:deleteBlacklist,
      refresh: '',
      format(res) {
        return res.map(data => {
          return data
        })
      }
    })
  ],
  data() {
    return {
      buttons: [],
      pageShow: true,
      dialogData:{},
      tableColumnAttributes: [
        { name: '充值号码', value: 'phone' },
        { name: '备注', value: 'note' },
      ],
      filters: {
        phone:'',
        note:''
      },
      form: {
        phone: '',
        note:'',
        id:''
      }
    }
  },
  methods: {
    async search(form){
      let para = {
        phone: this.filters.phone,
        start: 0,
        pageSize: 10,
        note:this.filters.note
      };
      this.searchOptions = para;
      this.setTableData()
    },
    onSubmit(){
      this.$confirm('确认提交吗？', '提示', {
        roundButton:true
      }).then( async () => {
        let para = Object.assign({}, this.form);
        para.id = "";
        const result = await updateBlacklist(para);
        this.resultApply(result);
      });
    }
  }
}
</script>
